package com.qd.flow;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cdqidi.util.page.PageUtil;
import com.qd.common.flow.domain.bill.FlowBillDTO;
import com.qd.common.flow.domain.bill.FlowQueryDTO;
import com.qd.common.flow.domain.index.IndexDTO;
import com.qd.common.sys.annotation.OperatorInfo;
import com.qd.common.sys.enums.OperatorType;
import com.qd.flow.service.workbench.WorkbenchService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 流程/WEB_工作台
 *
 * @author sjk
 * @create 2024-02-26 11:16
 * @since 1.0.0
 */
@RequiredArgsConstructor
@Validated
@RestController
@RequestMapping("/sys/workbench/")
@Slf4j
public class WorkbenchController {
    private final WorkbenchService workbenchService;

    /**
     * 首页
     *
     * @return 首页数据
     */
    @PreAuthorize("@ps.hasPermission('system:workbench:index')")
    @OperatorInfo(title = "首页", operator = OperatorType.OTHER)
    @GetMapping(value = "/index")
    public IndexDTO index() {
        return workbenchService.index();
    }

    /**
     * 待办任务列表
     *
     * @return 首页数据
     */
    @PreAuthorize("@ps.hasPermission('system:workbench:toDoTaskPage')")
    @OperatorInfo(title = "待办任务列表", operator = OperatorType.OTHER)
    @GetMapping(value = "/toDoTaskPage")
    public IPage<FlowBillDTO> toDoTaskPage(FlowQueryDTO dto) {
        return workbenchService.toDoTaskPage(PageUtil.buildPage(dto), dto);
    }

    /**
     * 已办任务列表
     *
     * @return 首页数据
     */
    @PreAuthorize("@ps.hasPermission('system:workbench:completedTaskPage')")
    @OperatorInfo(title = "已办任务列表", operator = OperatorType.OTHER)
    @GetMapping(value = "/completedTaskPage")
    public IPage<FlowBillDTO> completedTaskPage(FlowQueryDTO dto) {
        return workbenchService.completedTaskPage(PageUtil.buildPage(dto), dto);
    }
}